<template>
<div>
  {{msg}}
  <el-card>
    <div id="main"></div>
  </el-card>
</div>
</template>

<script>
// 导入 echarts
import echarts from 'echarts'
// 导入 lodash
import _ from 'lodash'

export default {
  data: function () {
    return {
      msg: '我是 reports 页面',
      option: {
        title: {
          text: '用户来源'
        },
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#E9EEF3'
            }
          }
        },
        grid: {
          left: '3%',
          right: '4%',
          bottom: '3%',
          containLabel: true
        },
        xAxis: [
          {
            boundaryGap: false
          }
        ],
        yAxis: [
          {
            type: 'value'
          }
        ]
      }
    }
  },
  async mounted() {
    var maEcharts = echarts.init(document.getElementById('main'))

    const { data: res } = await this.$http.get('reports/type/1')

    if(res.meta.status !== 200) {
      return this.$message({
        type: 'error',
        msg: '获取折线图数据失败'
      })
    }

    this.option = _.merge(this.option, res.data)
    console.log(res.data)
    maEcharts.setOption(this.option)
  }
}
</script>

<style>
#main {
  width: 800px;
  height: 600px;
}
</style>
